package com.eascs.admin.o2o.notify.service;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.admin.o2o.loan.service.O2OWorkFlowService;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.web.sso.User;
import com.eascs.web.sso.UserHolder;
import com.eascs.workflow.common.service.wf.WorkFlowNotify;
import com.eascs.workflow.common.vo.ModelResult;
import com.eascs.workflow.common.vo.WFNotifyParam;

/**
 * 工作流通知接口
 * 
 * @author user
 *
 */
@Service
public class WorkFlowNotifyService implements WorkFlowNotify {
	private static Logger log = LoggerFactory.getLogger(WorkFlowNotifyService.class);

	@Autowired
	private O2OWorkFlowService o2oWorkFlowService;

	@Override
	public ModelResult<Boolean> wfNotify(WFNotifyParam notifyParam) {
		log.info("接受来自工作的通知WorkFlowNotifyService[]:" , notifyParam);
		ModelResult<Boolean> modelResult = new ModelResult<Boolean>();
		User user=UserHolder.getUser();
		try {
			log.info("接受来自工作流APP notifyParam.getLoginUser不为空 UserHolder账户：[{}]", notifyParam.getLoginUser());
			if(UserHolder.getUser()==null){
				UserHolder.setUser(notifyParam.getLoginUser());
				log.info("设置APP UserHolder成功：{}",UserHolder.getUser().getCname());
			}
			modelResult = o2oWorkFlowService.wfNotify(notifyParam);
			return modelResult;
		} catch (Exception e) {
			log.info(notifyParam + ",处理工作的通知失败", e);
			modelResult.withError("", "").withStackTrace(e);
			return modelResult;
		}finally {
				UserHolder.setUser(user);
		}
	}

}
